/**
Group: efl/button (@since 1.23)
	 Part Text: efl.text (required)
	 Part Swallow: efl.background (required)
	 Part Swallow: efl.content (required)
	 Signal: efl,content,set
	 Signal: efl,content,unset
	 Signal: efl,state,animation,activated
	 Signal: efl,state,background,set
	 Signal: efl,state,background,unset
	 Signal: efl,state,disabled
	 Signal: efl,state,enabled
	 Signal: efl,text,set
	 Signal: efl,text,unset
Group: efl/button:anchor (@since 1.23)
	 Part Text: efl.text
	 Part Swallow: efl.background (required)
	 Part Swallow: efl.content (required)
	 Signal: efl,content,set
	 Signal: efl,content,unset
	 Signal: efl,state,animation,activated
	 Signal: efl,state,background,set
	 Signal: efl,state,background,unset
	 Signal: efl,state,disabled
	 Signal: efl,state,enabled
	 Signal: efl,text,set
	 Signal: efl,text,unset
*/
#define ICON         1
#define LABEL        2
#define MASK         3
#define DISABLE      4
#define PRESSED      8
#define BACKGROUND  16

group { name: "efl/button";
   data.item: "version" "123";
   script {
      BUTTONMODE_SCRIPT2
   }
   images.image: "win_shadow.png" COMP;
   parts {
      part { name: "shadow"; mouse_events: 0;
         scale: 1;
         description { state: "default" 0.0;
            rel.to: "base";
            WIN_SHADOW_SMALL;
            color_class: "/shadow/normal/button";
         }
         description { state: "pressed" 0.0; inherit;
            image.border_scale_by: 0.1;
            rel1.offset: -2 -1;
            rel2.offset: 0 1;
            color_class: "/shadow/pressed/button";
         }
         description { state: "disabled" 0.0; inherit;
            image.border_scale_by: 0.1;
            rel1.offset: -2 -1;
            rel2.offset: 0 1;
            color_class: "/shadow/disabled/button";
         }
      }
      rect { "base";
         scale: 1;
         desc { "default";
            color_class: "/bg/normal/button";
            rel1.offset: 2 2;
            rel2.offset: -3 -3;
            offscale;
         }
         desc { "pressed"; inherit;
            color_class: "/bg/pressed/button";
            rel1.offset: 3 3;
            rel2.offset: -4 -4;
            offscale;
         }
         desc { "disabled"; inherit;
            color_class: "/bg/disabled/button";
         }
         desc { "hidden"; inherit;
            visible: 0;
         }
      }
      swallow { "efl.background"; nomouse; required;
         desc { "default";
            rel.to: "base";
            visible: 0;
         }
         desc { "visible"; inherit;
            visible: 1;
         }
      }
      rect { "icon_clip";
         desc { "default";
            color: 255 255 255 255; // no cc
         }
         desc { "pressed"; inherit;
            color: 255 255 255 255; // no cc
         }
         desc { "disabled"; inherit;
            color: 255 255 255 64; // no cc
         }
      }
      swallow { "efl.content"; nomouse; required;
         clip_to: "icon_clip";
         scale: 1;
         desc { "default";
            fixed: 1 0;
            align: 0.0 0.5;
            rel1.offset: 6 6;
            rel2.relative: 0.0 1.0;
            rel2.offset: 6 -7;
            visible: 0;
            offscale;
         }
         desc { "visible"; inherit;
            fixed: 1 0;
            aspect: 1.0 1.0;
            visible: 1;
            min: ICMIN ICMIN;
         }
         desc { "icononly"; inherit;
            fixed: 0 0;
            align: 0.5 0.5;
            rel2.relative: 1.0 1.0;
            rel2.offset: -7 -7;
            visible: 1;
            min: ICMIN ICMIN;
         }
      }
      text { "efl.text"; nomouse; required;
         scale: 1;
         desc { "default";
            color_class: "/fg/normal/button";
            rel1.offset: 0 6;
            rel1.relative: 1.0 0.0;
            rel1.to_x: "efl.content";
            rel2.offset: -7 -7;
            text { font: FN; size: 10;
               align: 0.5 0.5;
               min: 0 0;
            }
            visible: 0;
            offscale;
            min: 0 ICMIN;
         }
         desc { "visible"; inherit;
            rel1.offset: 6 6;
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
         desc { "pressed_visible"; inherit;
            color_class: "/fg/pressed/button";
            rel1.offset: 6 6;
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
         desc { "textonly"; inherit;
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
         desc { "pressed_textonly"; inherit;
            color_class: "/fg/pressed/button";
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
         desc { "disabled_visible"; inherit;
            color_class: "/fg/disabled/button";
            rel1.offset: 6 6;
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
         desc { "disabled_textonly"; inherit;
            color_class: "/fg/disabled/button";
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
      }
      rect { "event";
         ignore_flags: ON_HOLD;
         desc { "default";
            color: 0 0 0 0; // no cc
         }
         desc { "disabled"; inherit;
            visible: 0;
         }
      }
   }
   programs {
      EFL_UI_CLICKABLE_PART_BIND("event")
      program { signal: "mouse,down,1"; source: "event";
         after: "button_click_anim";
      }
      program { name: "button_click_anim";
         script { flag_set(PRESSED); }
      }
      program { name: "button_unclick";
         signal: "mouse,up,1"; source: "event";
         after: "button_unclick_anim";
      }
      program { name: "button_unclick_anim";
         script { flag_unset(PRESSED); }
      }
      program { signal: "efl,state,animation,activated"; source: "efl";
         action: STATE_SET "pressed" 0.0;
         target: "shadow";
         target: "base";
         after: "button_unpressed_anim";
      }
      program { name: "button_unpressed_anim";
         in: 0.5 0.0;
         action: STATE_SET "default" 0.0;
         target: "shadow";
         target: "base";
      }
      program { signal: "efl,text,set"; source: "efl";
         script { flag_set(LABEL); }
      }
      program { signal: "efl,text,unset"; source: "efl";
         script { flag_unset(LABEL); }
      }
      program { signal: "efl,content,set"; source: "efl";
         script { flag_set(ICON); }
      }
      program { signal: "efl,content,unset"; source: "efl";
         script { flag_unset(ICON); }
      }
      program { signal: "efl,state,background,set"; source: "efl";
         script { flag_set(BACKGROUND); }
      }
      program { signal: "efl,state,background,unset"; source: "efl";
         script { flag_unset(BACKGROUND); }
      }
      program { signal: "efl,state,disabled"; source: "efl";
         script { flag_set(DISABLE); }
      }
      program { signal: "efl,state,enabled"; source: "efl";
         script { flag_unset(DISABLE); }
      }
   }
}

group { name: "efl/button:anchor";
   data.item: "version" "123";
   script {
      public btmode;
      public eval_mode(m) {
         new m1 = m & MASK;
         new d = m & DISABLE;
         new p = m & PRESSED;
         if (!d) {
            if (!p) {
               set_state(PART:"bar", "default", 0.0);
            }
            else {
               set_state(PART:"bar", "pressed", 0.0);
            }
         } else {
            set_state(PART:"bar", "disabled", 0.0);
         }
         if (m1 == (ICON | LABEL)) {
            if (!d) {
               set_state(PART:"efl.content", "visible", 0.0);
               if (!p) {
                  set_state(PART:"efl.text", "visible", 0.0);
               } else {
                  set_state(PART:"efl.text", "pressed_visible", 0.0);
               }
               set_state(PART:"icon_clip", "default", 0.0);
               set_state(PART:"event", "default", 0.0);
            } else {
               set_state(PART:"efl.content", "visible", 0.0);
               set_state(PART:"efl.text", "disabled_visible", 0.0);
               set_state(PART:"icon_clip", "disabled", 0.0);
               set_state(PART:"event", "disabled", 0.0);
            }
         } else if (m1 == (ICON)) {
            if (!d) {
               set_state(PART:"efl.content", "icononly", 0.0);
               set_state(PART:"efl.text", "default", 0.0);
               set_state(PART:"icon_clip", "default", 0.0);
               set_state(PART:"event", "default", 0.0);
            } else {
               set_state(PART:"efl.content", "icononly", 0.0);
               set_state(PART:"efl.text", "default", 0.0);
               set_state(PART:"icon_clip", "disabled", 0.0);
               set_state(PART:"event", "disabled", 0.0);
            }
         } else if (m1 == (LABEL)) {
            if (!d) {
               set_state(PART:"efl.content", "default", 0.0);
               if (!p) {
                  set_state(PART:"efl.text", "textonly", 0.0);
               } else {
                  set_state(PART:"efl.text", "pressed_textonly", 0.0);
               }
               set_state(PART:"icon_clip", "default", 0.0);
               set_state(PART:"event", "default", 0.0);
            } else {
               set_state(PART:"efl.content", "default", 0.0);
               set_state(PART:"efl.text", "disabled_textonly", 0.0);
               set_state(PART:"icon_clip", "disabled", 0.0);
               set_state(PART:"event", "disabled", 0.0);
            }
         } else {
            if (!d) {
               set_state(PART:"efl.content", "default", 0.0);
               set_state(PART:"icon_clip", "default", 0.0);
               set_state(PART:"event", "default", 0.0);
            } else {
               set_state(PART:"efl.content", "default", 0.0);
               set_state(PART:"icon_clip", "disabled", 0.0);
               set_state(PART:"event", "disabled", 0.0);
            }
         }
      }
   }
   parts {
      rect { "base";
         desc { "default";
            color: 0 0 0 0; // no cc
         }
         desc { "pressed"; inherit;
            inherit: "default";
         }
         desc { "disabled"; inherit;
            inherit: "default";
         }
         desc { "hidden"; inherit;
            inherit: "default";
         }
      }
      rect { "icon_clip";
         desc { "default";
         }
         desc { "disabled";
            inherit: "default";
            color: 255 255 255 64; // no cc
         }
      }
      swallow { "efl.background"; nomouse; required;
         desc { "default";
            rel.to: "base";
            visible: 0;
         }
         desc { "visible";
            inherit: "default";
            visible: 1;
         }
      }
      swallow { "efl.content"; nomouse; required;
         clip_to: "icon_clip";
         desc { "default";
            fixed: 1 0;
            align: 0.0 0.5;
            rel1.offset: 4 4;
            rel1.to: "base";
            rel2.relative: 0.0 1.0;
            rel2.offset: 4 -5;
            rel2.to: "base";
            visible: 0;
         }
         desc { "visible";
            inherit: "default";
            fixed: 1 0;
            aspect: 1.0 1.0;
            visible: 1;
            min: ICMIN ICMIN;
         }
         desc { "icononly";
            inherit: "default";
            fixed: 0 0;
            align: 0.5 0.5;
            rel2.relative: 1.0 1.0;
            rel2.offset: -5 -5;
            visible: 1;
            min: ICMIN ICMIN;
         }
      }
      text { "efl.text"; nomouse; required;
         scale: 1;
         desc { "default";
            rel1.offset: 0 4;
            rel1.relative: 1.0 0.0;
            rel1.to_x: "efl.content";
            rel1.to_y: "base";
            rel2.offset: -5 -5;
            rel2.to: "base";
            color_class: "/fg/normal/button-anchor";
            text { font: FN; size: 10;
               align: 0.5 0.5;
               min: 0 0;
            }
            visible: 0;
            min: 0 ICMIN;
         }
         desc { "visible";
            inherit: "default";
            rel1.offset: 4 4;
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
         desc { "pressed_visible";
            inherit: "default";
            color_class: "/fg/pressed/button-anchor";
            rel1.offset: 4 4;
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
         desc { "textonly";
            inherit: "default";
            rel1.offset: 0 4;
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
         desc { "pressed_textonly";
            inherit: "default";
            color_class: "/fg/pressed/button-anchor";
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
         desc { "disabled_visible";
            inherit: "default";
            rel1.offset: 0 0;
            color_class: "/fg/disabled/button-anchor";
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
         desc { "disabled_textonly";
            inherit: "default";
            rel1.offset: 0 4;
            color_class: "/fg/disabled/button-anchor";
            text.min: 1 1;
            text.ellipsis: -1;
            visible: 1;
         }
      }
      rect { "bar"; nomouse;
         desc { "default";
            color_class: "/fg/normal/button-anchor";
            rel1.relative: 0.0 1.0;
            rel1.offset: 2 -3;
            rel2.offset: -3 -3;
         }
         desc { "pressed";
            inherit: "default";
            color_class: "/fg/pressed/button-anchor";
         }
         desc { "disabled";
            inherit: "default";
            color_class: "/fg/disabled/button-anchor";
         }
      }
      rect { "event";
         desc { "default";
            color: 0 0 0 0; // no cc
         }
         desc { "disabled";
            inherit: "default";
            visible: 0;
         }
      }
   }
   programs {
      EFL_UI_CLICKABLE_PART_BIND("event")
      program { signal: "mouse,down,1"; source: "event";
         after: "button_click_anim";
      }
      program { name: "button_click_anim";
         script {
            new m = get_int(btmode);
            m |= PRESSED; set_int(btmode, m);
            eval_mode(m);
         }
      }
      program { signal: "mouse,up,1"; source: "event";
         after: "button_unclick_anim";
      }
      program { name: "button_unclick_anim";
         script {
            new m = get_int(btmode);
            m &= ~PRESSED; set_int(btmode, m);
            eval_mode(m);
         }
      }
      program { signal: "efl,state,animation,activated"; source: "efl";
         action: STATE_SET "pressed" 0.0;
         target: "base";
         after: "button_unpressed_anim";
      }
      program { name: "button_unpressed_anim";
         action: STATE_SET "default" 0.0;
         in: 0.5 0.0;
         target: "base";
      }
      program { signal: "efl,text,set"; source: "efl";
         script {
            new m = get_int(btmode);
            m |= LABEL; set_int(btmode, m);
            eval_mode(m);
         }
      }
      program { signal: "efl,text,unset"; source: "efl";
         script {
            new m = get_int(btmode);
            m &= ~LABEL; set_int(btmode, m);
            eval_mode(m);
         }
      }
      program { signal: "efl,content,set"; source: "efl";
         script {
            new m = get_int(btmode);
            m |= ICON; set_int(btmode, m);
            eval_mode(m);
         }
      }
      program { signal: "efl,content,unset"; source: "efl";
         script {
            new m = get_int(btmode);
            m &= ~ICON; set_int(btmode, m);
            eval_mode(m);
         }
      }
      program { signal: "efl,state,background,set"; source: "efl";
         action: STATE_SET "visible" 0.0;
         target: "efl.background";
      }
      program { signal: "efl,state,background,unset"; source: "efl";
         action:  STATE_SET "default" 0.0;
         target: "efl.background";
      }
      program { signal: "efl,state,disabled"; source: "efl";
         script {
            new m = get_int(btmode);
            m |= DISABLE; set_int(btmode, m);
            eval_mode(m);
         }
      }
      program { signal: "efl,state,enabled"; source: "efl";
         script {
            new m = get_int(btmode);
            m &= ~DISABLE; set_int(btmode, m);
            eval_mode(m);
         }
      }
   }
}
